package it.eg.managedcor.example;

import it.eg.managedcor.exceptions.RollbackException;
import it.eg.managedcor.impl.TaskExecutionResult;
import it.eg.managedcor.interfaces.RollbackableTask;

import org.apache.log4j.Logger;

public class Task1 implements TestProcessTask{
	
	private static final Logger log = Logger.getLogger(Task1.class);

	@Override
	public TaskExecutionResult performTask(TestProcessSession sessionData) {
		int contatore = sessionData.getProcessInput().getCounter();
		++contatore;
		sessionData.setPartialCounter(contatore);
		log.debug(" performTask - Counter increased. Actual Value: " + sessionData.getPartialCounter());
		return TaskExecutionResult.PERFORMED_CONTINUE_EXECUTION;
	}

	@Override
	public void rollback(TestProcessSession sessionData) throws RollbackException {
		int contatore = sessionData.getPartialCounter();
		--contatore;
		sessionData.setPartialCounter(contatore);
		log.debug(" rollback - Counter dencreased. Actual Value: " + sessionData.getPartialCounter());
	}

}
